<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>为用户设置园区关联关系</title>
<%@ include file="/WEB-INF/sys/include/css.jsp" %>
<link href="${path}/res/js/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
div.form div.item #ztreeWrapper{border:1px solid #999;width:600px;height:500px;overflow:auto;background-color:#fff;}
div.form div.item .ztree{}
</style>
</head>
<body>
<form id="form1" method="post" action="${path}/userPark/saveUserParkRels.json"></form>
<div class="form">
	<div class="title">为用户设置园区关联关系</div>
	<div class="group" style="margin-bottom:0;">
		<div class="text">选择园区（地块）:</div>
	</div>
	<div class="group">
		<div class="label" style="width:40px;">&nbsp;</div>
		<div class="item"><div id="ztreeWrapper"><ul id="parkTree" class="ztree"></ul></div></div>
	</div>
	<div class="buttons" style="width:650px;">
		<button class="highlight" id="submit1" type="button">确定</button>
		<button type="button" id="cancel1">取消</button>
	</div>
</div>
<%@ include file="/WEB-INF/sys/include/script.jsp" %>
<script src="${path}/res/js/ztree/jquery.ztree.all-3.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var zTreeObj, scrollObj;
$(function (){
	var ztreeWrapper = $('#ztreeWrapper');
	var parkTree = $("#parkTree");
	scrollObj = ztreeWrapper.niceScroll(parkTree, $.extend(true, {}, $.qxNiceScrollOpts || {}, {
		cursoropacitymin:0.5,
	    cursoropacitymax:0.8,
	    bouncescroll:false,
	    cursorwidth:"5px"
	  }));
	ztreeWrapper.unbind('focus.niceScroll').bind('focus.niceScroll', function(){ztreeWrapper.blur();});
	
	zTreeObj = $.fn.zTree.init(parkTree, {
 		async:{
	 		enable:true, type:"get",
			url: "${path}/userPark/getSetParkData.json?userid=${userid}"
		},
		data:{
			simpleData:{enable:true, idKey:'id', pIdKey:'pid'},
			key:{checked:"hasRights", name:"name", title:"name"}
		},
		view:{showIcon:false},
		check:{enable:true, chkboxType:{"Y":"ps", "N":"s"}},
		callback:{
			onAsyncSuccess:function(event, treeId){
	 	 		pageResize();
	 	 	},
	 	 	onExpand: function(){pageResize();},
	 	 	onCollapse: function(){pageResize();}
 	 	}
	});
	
	$("#submit1").click(function(){
		UiUtil.lockButton('submit1');
		setParks();
	});

	$("#cancel1").click(function(){
		UiUtil.closeForm();
	});
	
});

var ART_DIALOG_WINDOW_ID = 'setUserParks_page';

function pageResize(){
	scrollObj.onResize();
	window.setTimeout(function(){scrollObj.onResize();}, 300);
}

//保存角色分配
function setParks(){
	artConfirm('<p style="line-height:50px"><b>确认按照当前选择设置用户-园区关联关系吗？<b></p>', function (){
		var form1 = $("#form1");
		form1.empty();
		var nodes = zTreeObj.getCheckedNodes(true);
		for(var i=0; i<nodes.length; i++){
			var node = nodes[i];
			if(node.datatype == 'comp'){
				form1.append('<input type="hidden" name="companyid" value="'+node.id+'" />');
			}else if(node.datatype == 'park'){
				form1.append('<input type="hidden" name="parkid" value="'+node.id+'" />');
			}else if(node.datatype == 'block'){
				form1.append('<input type="hidden" name="blockid" value="'+node.id+'" />');
			}
		}
		form1.append('<input type="hidden" name="userid" value="${userid}" />');
		
		form1.ajaxForm(function(data){
			UiUtil.isSuccess(data, "设置用户-园区关联关系成功", function(){
				form1.empty();
				UiUtil.closeForm();
			});
		});
		
		form1.submit();
	});
	
}

</script>
</body>
</html>